package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntReportCoachMapper;
import com.prd.model.EntReportCoach;
import com.prd.model.LoginUser;
import com.prd.service.EntReportCoachService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EntReportCoachServiceImpl extends ServiceImpl<EntReportCoachMapper, EntReportCoach> implements EntReportCoachService {

    @Autowired
    private EntReportCoachMapper entReportCoachMapper;

    @Override
    public int insertInfo(EntReportCoach entReportCoach) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entReportCoach);
        return entReportCoachMapper.insert(entReportCoach);
    }

    @Override
    public int updateInfo(EntReportCoach entReportCoach) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entReportCoach);
        return entReportCoachMapper.updateById(entReportCoach);
    }

    @Override
    public List<EntReportCoach> listInfo(EntReportCoach entReportCoach) {
        LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.setEntity(entReportCoach);
        return entReportCoachMapper.selectList(lambdaQueryWrapper);
    }
}
